package com.shop.loan.model;

import com.shop.loan.util.LoanOrderUtil;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Drill;
import xyz.erupt.annotation.sub_erupt.Link;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.Readonly;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.BoolType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "s_loan_order_bill")
@Erupt(
        name = "订单账单表",
        authVerify = false,
        power = @Power(add = false, edit = false, viewDetails = false, delete = false),
        drills = {
                @Drill(code = "drill",
                        title = "还款记录",
                        link = @Link(linkErupt = LoanOrderPayLog.class,  //关联表
                                joinColumn = "billId")),  //关联表达式
        }
)
@Getter
@Setter
public class LoanOrderBill extends BaseModel {


    @Column(name = "order_id")
    private Long orderId;


    private Integer totalPeriod;

    @EruptField(
            views = @View(title = "第几期"),
            edit = @Edit(title = "第几期", notNull = true)
    )
    private Integer period;


    @EruptField(
            views = @View(title = "本金"),
            edit = @Edit(title = "本金", notNull = true)
    )
    private BigDecimal money;

    @EruptField(
            views = @View(title = "利息金额"),
            edit = @Edit(title = "利息金额")
    )
    private BigDecimal rateMoney = BigDecimal.ZERO;


    private BigDecimal overdueFine;


    @EruptField(
            views = @View(title = "已还本息", width = LoanOrderUtil.orderListByPayMoneyWidth),
            edit = @Edit(title = "已还本息")
    )
    private BigDecimal payMoney = BigDecimal.ZERO;


    @EruptField(
            views = @View(title = "优惠本息"),
            edit = @Edit(title = "优惠本息")
    )
    private BigDecimal discountsMoney = BigDecimal.ZERO;

    @EruptField(
            views = @View(title = "还款日"),
            edit = @Edit(title = "还款日",
                    readonly = @Readonly,
                    dateType = @DateType(type = DateType.Type.DATE))
    )
    private Date payTime;


    @EruptField(
            views = @View(title = "支付状态"),
            edit = @Edit(
                    title = "支付状态",
                    type = EditType.BOOLEAN,
                    boolType = @BoolType(
                            trueText = "已支付",
                            falseText = "未支付"
                    )
            )
    )
    private Boolean payStatus = false;


    @EruptField(
            views = @View(title = "当前逾期"),
            edit = @Edit(
                    title = "当前逾期",
                    type = EditType.BOOLEAN,
                    boolType = @BoolType(
                            trueText = "正常",
                            falseText = "逾期"
                    )
            )
    )
    private Boolean overdueStatus = true;

    @EruptField(
            views = @View(title = "逾期天数"),
            edit = @Edit(
                    title = "逾期天数"
            )
    )
    private Integer overdueDay;

    @EruptField(
            views = @View(title = "最后还款时间"),
            edit = @Edit(title = "最后还款时间",
                    readonly = @Readonly,
                    dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private Date opTime;

}
